import pymysql

# 打开数据库连接，不指定数据库
conn = pymysql.connect(host='localhost', user='root', password='root', port=3306, )
conn.select_db('test')

# 获取游标
cur = conn.cursor()

cur.execute("select * from test;")
while 1:
    res = cur.fetchone()
    if res is None:
        # 表示已经取完结果集
        break
    print(res)
cur.close()
conn.commit()
conn.close()
print('sql执行成功')
